﻿// =================================================================== 
// 业务逻辑层(GDIT.BLL)
//====================================================================
// 文件：DataProvider.cs
// 项目名称：学院网站
// 创建时间：2012-08-08
// 负责人：ChenZhiGang
// 程序集介绍：数据访问链接库
// ===================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GDIT.BLL
{

    //每一次更改DAL层的东西都要重新生成DAL后，把DAL.dll复制到DataProviders

    internal class DataProvider//只在本程序集中能够引用到这个类
    {
        private static Pattern.DALAbstractFactory instance = null;

        static DataProvider()
        {
            //.NET能保证这里的代码只执行一次
            //根据web.config动态反射实例化数据工厂的实例(提供程序的DLL文件名，类名（完整名称（命名空间.类名））)
            string dllFileName = System.Web.Configuration.WebConfigurationManager.AppSettings["DataProviderDllFile"];
            string dalFactoryClassName = System.Web.Configuration.WebConfigurationManager.AppSettings["DataProviderFactoryName"];
            System.Reflection.Assembly dll = System.Reflection.Assembly.LoadFile(
                System.Web.HttpContext.Current.Server.MapPath("~/DataProviders/" + dllFileName)
                );//动态加载一个程序集（exe,dll）
            instance = dll.CreateInstance(dalFactoryClassName) as Pattern.DALAbstractFactory;
            //通过一个类的全名，创建它的实例
        }

        private DataProvider() { }

        public static Pattern.DALAbstractFactory defaultProvider
        {
            get
            {
                return instance;
            }
        }
    }
}
